class VideosController < ApplicationController
  
  before_filter :load_video, :only => [ :show ]
  before_filter :load_videos, :only => [ :index ]
  before_filter :find_tagged, :only => [ :tagged ]
  
  layout "two_column"

  protected
  def load_videos
    @videos = Video.paginate(:page => params[:page], :order => 'created_at DESC')
  end

  def load_video
    @video = Video.find(params[:id])
  end

  def find_tagged
    @videos = Video.find_tagged_with(params[:tag])
  end

  public
  def index
    respond_to do |format|
      format.html
      format.rss {render :layout => false}
      format.xml  { render :xml => @videos }
    end
  end

  def show          
    respond_to do |format|
      format.html
      format.xml  { render :xml => @video }
    end
  end

  def tagged
    respond_to do |format|
      format.html
      format.rss {render :layout => false}
      format.xml  { render :xml => @videos }
    end
  end

end
